#include <iostream>
#include "gui.h"

Gui::Gui(QWidget *parent)
	: _icon(*this)
{
	_icon.init();
}

Gui::~Gui()
{
}

apiGui				*Gui::getApi()
{
	return (new apiGui(this));
}

const QString 		Gui::getIp() const
{
	return (_icon.getDialog()->getIp());
}

const QString 		Gui::getPort() const
{
	return (_icon.getDialog()->getPort());
}

bool				Gui::isInfoFilled()
{
	if (_icon.getDialog()->getIp().isEmpty() || _icon.getDialog()->getPort().isEmpty())
		return (false);
	return (true);
}

quint16				Gui::isInfoValid()
{
	connectInfo					info = connectInfo(QHostAddress(getIp()), getPort().toInt());

	if (QAbstractSocket::IPv4Protocol != info._ip.protocol() &&
		QAbstractSocket::IPv6Protocol != info._ip.protocol())
		return 1;
	if (info._port == 0)
		return 2;
	return 0;
}

void				Gui::connectError(quint16 error)
{
	if (getIp().isEmpty() || error == 1)
		std::cout << "Ip Adress is missing" << std::endl;
	if (getPort().isEmpty() || error == 2)
		std::cout << "Port is missing" << std::endl;
}